// app.js
const {
  validLogin
} = require('./utils/util');
App({
  onLaunch() {
    // 展示本地存储能力
    const logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)

    // 登录
    wx.login({
      success: res => {
        // 发送 res.code 到后台换取 openId, sessionKey, unionId
      }
    })
  },
  onShow() {
    validLogin();
  },
  globalData: {
    userInfo: null,

    //当前播放歌曲信息:(Id,name,songer,album)
    correctSongId: null, //ID
    correctSongName: null, //歌曲名
    correctSongArtists: [], //歌手s
    correctSongArtist: null,
    correctSongAlbum: null, //专辑
    ifStop: true, //暂停开始判断条件
    songImg: null, //歌曲图标
    songPlayUrl: null, // 歌曲播放URL
    songComments: [], //歌曲评论
    songDuration: null, //歌曲时长
    songCurrentTime: null, //歌曲当前时间
    //当前播放的歌单里所有歌曲列表
    correctSongList: [],
    //当前播放的歌在歌单的编号
    index: null,

    refreshListId: null //触底时歌单Id
  },

  //监听函数
  watch: function (changeName, changeImg, changeArtist, changeIfStop) {
    var obj = this.globalData

    //监听name
    Object.defineProperty(obj, 'correctSongName', {
      configurable: true,
      enumerable: true,
      set: function (value) {
        this._correctSongName = value;
        changeName(value)
      },
      get: function () {
        return this._correctSongName
      }
    })

    //监听Img
    Object.defineProperty(obj, 'songImg', {
      configurable: true,
      enumerable: true,
      set: function (value) {
        this._songImg = value;
        changeImg(value)
      },
      get: function () {
        return this._songImg
      }
    })

    //监听Artist
    Object.defineProperty(obj, 'correctSongArtist', {
      configurable: true,
      enumerable: true,
      set: function (value) {
        this._correctSongArtist = value;
        changeArtist(value)
      },
      get: function () {
        return this._correctSongArtist
      }
    })

    //监听ifStop
    Object.defineProperty(obj, 'ifStop', {
      configurable: true,
      enumerable: true,
      set: function (value) {
        this._ifStop = value;
        changeIfStop(value)
      },
      get: function () {
        return this._ifStop
      }
    })
  },
  watchStop: function (changeIfStop) {
    var obj = this.globalData
    //监听ifStop
    Object.defineProperty(obj, 'ifStop', {
      configurable: true,
      enumerable: true,
      set: function (value) {
        this._ifStop = value;
        changeIfStop(value)
      },
      get: function () {
        return this._ifStop}
      })
    },
    
  watch1: function (changeNowtime) {
    var obj = this.globalData
    //监听name
    Object.defineProperty(obj, 'songCurrentTime', {
      configurable: true,
      enumerable: true,
      set: function (value) {
        this._songCurrentTime = value;
        changeNowtime(value)
      },
      get: function () {
        return this._songCurrentTime
      }
    })
  }
})